/**
 * weapp-js v2.2.3(2022-4-26)
 * https://codeup.aliyun.com/motigo/motigo/weapp_base
 * Copyright@ 2022 Motigo, Inc.
 * 
 */
class UI {
    constructor() {}
    imageCropInit(opts) {
        return new Promise((resolve, reject) => {
            this._getUIRoot().then(node => {
                node.imageCropInit(opts)
                    .then(res => {
                        node.closeCropComponent();
                        resolve(res);
                    })
                    .catch(err => {
                        node.closeCropComponent();
                        reject(err);
                    });
            });
        });
    }
    login(opts) {
        console.log('ui login');
        return new Promise((resolve, reject) => {
            this._getUIRoot().then(page => {
                if (page) {
                    let loginComp = page.selectComponent('#weapp_login');
                    loginComp
                        .login(opts)
                        .then(res => {
                            resolve(res);
                        })
                        .catch(err => {
                            reject(err);
                        });
                } else {
                    // 没有找到page节点
                    reject({ msg: 'no page element' });
                }
            });
        });
    }
    _getUIRoot() {
        return new Promise((resolve, reject) => {
            const pages = getCurrentPages();
            const page = pages.length > 0 ? pages[pages.length - 1] : null;
            resolve(page);
        });
    }
}

export default new UI();
